package com.zhongfl.crm.api.view;

import com.github.pagehelper.PageInfo;
import com.zhongfl.crm.enums.LxMessageLogDealStatus;
import com.zhongfl.crm.enums.LxMessageType;
import com.zhongfl.crm.model.LxMessageLog;
import com.zhongfl.crm.model.KeyValuePair;
import com.zhongfl.crm.request.LxMessageLogRequest;
import com.zhongfl.crm.service.LxMessageLogService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import tech.heptagram.core.common.rest.ResponseResult;

/**
 * @author 奈良鹿丸
 * @date 2018/9/30
 */
@RestController
@RequestMapping("/api/view/messageLog")
public class LxMessageLogController {

    @Resource
    private LxMessageLogService lxMessageLogService;

    @PostMapping("/findByPage")
    public ResponseResult<PageInfo<LxMessageLog>> findByPage(@RequestBody LxMessageLogRequest lxMessageLogRequest){
        PageInfo<LxMessageLog> pageInfo = lxMessageLogService.findByPage(lxMessageLogRequest);
        return new ResponseResult<>(pageInfo);
    }

    @GetMapping("/reset/{id}")
    public ResponseResult reset(@PathVariable Long id){
        lxMessageLogService.reset(id);
        return new ResponseResult();
    }

    @GetMapping("/findAllType")
    public ResponseResult<List<KeyValuePair>> findAllType(){
        List<KeyValuePair> types = new ArrayList<>();
        for (LxMessageType dealType : LxMessageType.values()) {
            types.add(new KeyValuePair(dealType.toString(), dealType.toString()));
        }
        return new ResponseResult<>(types);
    }

    @GetMapping("/findAllStatus")
    public ResponseResult<List<KeyValuePair>> findAllStatus(){
        List<KeyValuePair> status = new ArrayList<>();
        for (LxMessageLogDealStatus dealStatus : LxMessageLogDealStatus.values()) {
            status.add(new KeyValuePair(dealStatus.getValue().toString(),dealStatus.getDesc()));
        }
        return new ResponseResult<>(status);
    }
}
